package com.netty.admin.controller;

import com.netty.admin.service.GroupService;
import com.netty.common.annotation.Log;
import com.netty.common.entity.bo.GroupFormBo;
import com.netty.common.entity.bo.GroupMemberFormBo;
import com.netty.common.entity.result.Result;
import com.netty.common.enums.BusinessType;
import com.netty.common.enums.OperatorType;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.GroupSequence;
import javax.validation.Valid;

/**
 * @author LiuXiaoYu
 * @date 2022/2/8- 14:08
 */
@RestController
@RequestMapping("/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @PostMapping("/addGroup")
    @Log(title = "增加群组",businessType = BusinessType.INSERT,operatorType = OperatorType.USER)
    public Result<?> addGroup(@RequestBody @Validated GroupFormBo groupFormBo){
     return groupService.addGroup(groupFormBo);
    }

    /**
     * 获取该用户创建的所有群组
     * @return
     */
    @GetMapping("/getAllGroups")
    @Log(title = "获取用户创建的所有群组",businessType = BusinessType.GET,operatorType = OperatorType.USER)
    public Result<?> getAllGroups(){
        return groupService.getAllGroups();
    }

    /**
     * 获取用户加入的所有群组
     * @return
     */
    @GetMapping("/allAlreadyJoinedGroups")
    @Log(title = "获取用户加入的所有群组",businessType = BusinessType.GET,operatorType = OperatorType.USER)
    public Result<?> getAlreadyJoinedGroups(){
        return groupService.getAlreadyJoinedGroups();
    }

    /**
     * 给一个群添加群成员
     * @param groupMemberFormBo
     * @return
     */
    @PostMapping("/addMember")
    @Log(title = "添加群成员",businessType = BusinessType.INSERT,operatorType = OperatorType.USER)
    public Result<?> addMember(@RequestBody @Validated GroupMemberFormBo groupMemberFormBo){
        return groupService.addMember(groupMemberFormBo);
    }



}
